package com.kehao.leetcode.jzoffer;

import org.junit.Test;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/22 17:26
 */
public class JZSolution019 {
    public boolean validPalindrome(String s) {
        int length = s.length();
        int left = 0,right = length-1;
        while (left<right) {
            if(s.charAt(left)==s.charAt(right)){
                left ++;
                right --;
            }else {
                boolean result1 = false,result2 = false;
                if(s.charAt(left+1)==s.charAt(right)){
                    left++;
                    result1 = validPalindrome(s, left, right);
                    left --;
                }

                if (s.charAt(left)==s.charAt(right-1)) {
                    right--;
                    result2 = validPalindrome(s, left, right);
                }
                return result1||result2;
            }
        }
        return true;
    }

    private boolean validPalindrome(String s,int left,int right){
        while (left<right) {
            if(s.charAt(left)!=s.charAt(right)){
                return false;
            }
            left++;
            right --;
        }
        return true;
    }

    @Test
    public void test01(){
        String str = "aguokepatgbnvfqmgmlcupuufxoohdfpgjdmysgvhmvffcnqxjjxqncffvmhvgsymdjgpfdhooxfuupuculmgmqfvnbgtapekouga";
        boolean b = validPalindrome(str);
        System.out.println(b);
    }
}
